package org.dingfugui.triple.protocol.binary.aio;

import org.dingfugui.triple.link.Link;
import org.dingfugui.triple.protocol.Translator;
import org.dingfugui.triple.proxy.ProxyHandler;
import org.dingfugui.triple.rpc.RequestMessage;
import org.dingfugui.triple.rpc.ResponseMessage;

/**
 * Created by fugui.ding on 2015/6/10.
 */
public class AioProxyHandler implements ProxyHandler {

    AioRequestHandler requestHandler;
    Link link;
    Translator messageHandler;

    public AioProxyHandler(Link link, Translator messageHandler) {
        this.link = link;
        this.messageHandler = messageHandler;
        this.requestHandler = new AioRequestHandler(link, messageHandler);
    }

    @Override
    public Object invoke(String path, String method, Class<?>[] types, Object[] params) {
        RequestMessage requestMessage = new RequestMessage(path, method, types, params);
        ResponseMessage responseMessage = requestHandler.handle(requestMessage);
        Object result = responseMessage.getResult();
        return result;
    }
}
